package pers.hl.module_main.mine

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.FragmentUtils
import pers.hl.common.base.BaseVBActivity
import pers.hl.lib_global.common.MMKVHelper
import pers.hl.module_main.R
import pers.hl.module_main.common.PageHelper
import pers.hl.module_main.databinding.ActivityMineMemuBinding

class MineMenuActivity: BaseVBActivity<ActivityMineMemuBinding>() {

    private var mMenuType = DEFAULT_MENU_TYPE

    companion object {
        const val KEY_MENU_TYPE = "key_menu_type"
        const val DEFAULT_MENU_TYPE = 0x01

        const val TYPE_SHARE = 0x020
        const val TYPE_FOLLOW = 0x030
        const val TYPE_FANS = 0x040

        const val TYPE_TAG_BOOK = 0x050

    }

    override fun initView(savedInstanceState: Bundle?) {
        intent.apply {
            mBinding.apply {
                mMenuType = getIntExtra(KEY_MENU_TYPE, DEFAULT_MENU_TYPE)
                if (mMenuType == MineMenu.MENU_USER) {
                    PageHelper.startUserHomePage(mContext, MMKVHelper.getUser()!!.userId)
                    finish()
                    return
                }
                val fragment: Fragment = when (mMenuType) {
                    MineMenu.MENU_PUBLISH -> MyPublishFragment.newInstance()
                    MineMenu.MENU_BORROW -> MyBorrowFragment()
                    MineMenu.MENU_COLLECTION -> CollectFragment()
                    MineMenu.MENU_COMMENT -> MyCommentFragment()
                    TYPE_SHARE -> MyShareFragment.newInstance()
                    TYPE_FOLLOW -> UserListFragment.newInstance(UserListFragment.TYPE_FOLLOW)
                    TYPE_FANS -> UserListFragment.newInstance(UserListFragment.TYPE_FANS)
                    TYPE_TAG_BOOK -> TagFragment()
                    else -> MyBorrowFragment()
                }
                openPage(fragment)
            }
        } ?: finish()
    }

    override fun initData(savedInstanceState: Bundle?) {

    }

    fun openPage(fragment: Fragment, bundle: Bundle? = null) {
        FragmentUtils.replace(supportFragmentManager, fragment, R.id.fl_container)
    }
}